<?php
include dirname(dirname(__FILE__)).'/admin-verify.php';
include dirname(__FILE__).'/functions.php';
?>

<!DOCTYPE html>
<html>
<head>
		<?php include dirname(dirname(dirname(__FILE__))).'/include/common-header.php' ?>
		<script type="text/javascript">
		$(document).ready(function (){
			$(".delete-btn").click(function() {
				if(confirm("确认删除？"))return true;
				return false;
			});
		});</script>
		<link rel="stylesheet" type="text/css" href="../css/style.css">
		<title>员工管理</title>
</head>
<body>
	<div class="col-md-12">
		<div>
			<h3>员工管理</h3>
		</div>
		<div>
			  	<table class="table table-striped table-bordered table-hover table-condensed" id="default-table">
				  <tr>
				  	<th>用户名</th>
				  	<th>学号</th>
				  	<th>姓名</th>
				  	<th>性别</th>
				  	<th>年级</th>
				  	<th>学院</th>
				  	<th>联系方式</th>
				  	<th>身份</th>
				  	<th>是否轮值</th>
				  	<th>操作</th>
				  </tr>
				  <?php 
				  		$items = getAllUser();
				  		$item_cnt = 0;
				  		foreach ($items as $item) {
				  			$item_cnt++;
				  			echo '
				  			<tr>
				  				<td>'.$item["username"].'</td>
				  				<td>'.$item["student_id"].'</td>
				  				<td>'.$item["user_real_name"].'</td>
				  				<td>'.$item["sex"].'</td>
				  				<td>'.$item["grade"].'</td>
				  				<td>'.$item["department"].'</td>
				  				<td>'.$item["phone"].'</td>
				  				<td>'.$item["user_role"].'</td>
				  				<td>';
				  					if($item["is_user_on_duty"]==1)echo "是";
				  					else echo "否";
				  				echo '</td>
				  				<td>';
				  				if(($_SESSION['user_role']=="admin"||$_SESSION['user_role']=="super_admin")&&$item["user_role"]=="user"
				  					||$_SESSION['user_role']=="super_admin"
				  					&&$item["user_role"]=="admin") {
				  					echo '
				  					<a href="edit-user.php?id='.$item["id"].'">编辑</a>
				  					<a href="delete-user.php?id='.$item["id"].'" class="delete-btn">删除</a> ';
				  				}
				  				if($_SESSION['user_role']!='user') {
				  					echo '
				  					<a href="user-info-detail.php?id='.$item["id"].'">详细资料</a>
				  					';
				  				}
				  				echo '
				  				</td>
				  			</tr>
				  			'; 
				  		}

				  ?>

				</table>
				<h4>当前用户数:<?php echo $item_cnt; ?></h4>
			  </div>
			  <div class="tab-pane fade form-content" id="add-user">
			  		
		</div>
	</div>
	
</body>
</html>